import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/http/http.dart';
import 'package:enterprise_v6_app/app/core/utils/interface.dart';
import 'package:enterprise_v6_app/app/data/entities/application/major_hazard/hazard_obligation_history_entity.dart';

class HazardObligationsViolationController extends GetxController {
  final year = HazardViolationYearType.current.obs;

  Future<List<HazardObligationHistoryEntity>> dataLoad(
    int idx,
    int size,
    String controlId,
    String type,
  ) async {
    final res = await HttpUtil().generateGetRequest<List<HazardObligationHistoryEntity>>(
      Interface.getHazardObligationMissionHistory,
      queryParameters: {
        'startTime': year.value.startTime,
        'endTime': year.value.endTime,
        'workType': type,
        'controlId': controlId,
        'pageNum': idx,
        'pageSize': size,
      },
    ).execute();
    return res.data ?? [];
  }
}

enum HazardViolationYearType {
  current,
  last,

  /// 前年
  beforeLast,
  ;

  String get name {
    switch (this) {
      case HazardViolationYearType.current:
        return '本年';
      case HazardViolationYearType.last:
        return '去年';
      case HazardViolationYearType.beforeLast:
        return '前年';
    }
  }

  String get startTime {
    switch (this) {
      case HazardViolationYearType.current:
        return '${DateTime.now().year}-01-01 00:00:00';
      case HazardViolationYearType.last:
        return '${DateTime.now().year - 1}-01-01 00:00:00';
      case HazardViolationYearType.beforeLast:
        return '${DateTime.now().year - 2}-01-01 00:00:00';
    }
  }

  String get endTime {
    switch (this) {
      case HazardViolationYearType.current:
        return '${DateTime.now().year}-12-31 23:59:59';
      case HazardViolationYearType.last:
        return '${DateTime.now().year - 1}-12-31 23:59:59';
      case HazardViolationYearType.beforeLast:
        return '${DateTime.now().year - 2}-12-31 23:59:59';
    }
  }
}
